<?php

namespace App\Domain\Visitlist\Services;

use App\Domain\Visitlist\Dao\VisitlistDao;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use App\Domain\Visitlist\Models\VisitlistModel;

class VisitlistService
{
    public function list($params)
    {
        $query = VisitlistModel::query()
            ->select('visitlist.*')
            ->where('visitlist.state', 1);
        $query = $query->where(function (Builder $query) use ($params) {
            if (isset($params['uid']))
                $query->where('uid', $params['uid']);
        });
        if (isset($params['pageSize']) && isset($params['currentPage'])) {
            return $query->paginate($params['pageSize'], ['*'], 'page', $params['currentPage']);
        } else {
            return $query->get();
        }
    }

    public function create($param){
        $visitlistDao = new VisitlistDao();
        $res = $visitlistDao->create([
            'uid' => $param['memberId'],
            'description' => $param['description'],
            'diagnosis' => $param['diagnosls'],
            'date' => $param['date'],
            'room' => $param['room'],
        ]);
        return $res;
    }
}
